package com.mall.user.domain.model;

import com.mall.goods.common.enums.BillCycleType;
import com.mall.goods.common.util.Common;
import com.mall.goods.common.util.State;
import com.mall.goods.common.config.ShopConfig;
import io.micrometer.common.util.StringUtils;
import lombok.Data;

import java.sql.Timestamp;

/**

 *
 * 店铺实体
 *
 *
 * Created 2017/4/17 11:33
 */
@Data
public class Store {
    /**
     * 店铺编号
     */
    private int storeId;
    /**
     * 店铺名称
     */
    private StoreName storeName;
    /**
     * 店铺等级编号
     */
    private int gradeId;
    /**
     * 店铺等级名称
     */
    private String gradeName;
    /**
     * 商家编号
     */
    private int sellerId;
    /**
     * 商家用户名
     */
    private SellerName sellerName;
    /**
     * 店铺分类编号
     */
    private int classId;
    /**
     * 店铺分类名称
     */
    private String className;
    /**
     * 店铺状态</br>
     * 0-关闭 1-开启
     */
    private int state;
    /**
     * 店铺地址
     */
    private String storeAddress;
    /**
     * 店铺创建时间
     */
    private Timestamp storeCreateTime;
    /**
     * 店铺过期时间
     */
    private Timestamp storeEndTime;
    /**
     * 店铺Logo
     */
    private String storeLogo= "";
    /**
     * 店铺横幅
     */
    private String storeBanner = "";
    /**
     * 店铺头像
     */
    private String storeAvatar = "";
    /**
     * 店铺seo关键字
     */
    private StoreSeoKeywords storeSeoKeywords = StoreSeoKeywords.of("");
    /**
     * 店铺seo描述
     */
    private StoreSeoDescription storeSeoDescription = StoreSeoDescription.of("");
    /**
     * 店铺商家电话
     */
    private StorePhone storePhone = StorePhone.of("");
    /**
     * 店铺主营商品
     */
    private StoreZy storeZy = StoreZy.of("");
    /**
     * 是否推荐店铺</br>
     * 0-否 1-是，默认为0
     */
    private int isRecommend = 0;
    /**
     * 店铺当前主题
     */
    private String storeTheme = "default";
    /**
     * 描述相符度分数
     */
    private double storeDesccredit = 5.0;
    /**
     * 服务态度分数
     */
    private double storeServicecredit = 5.0;
    /**
     * 发货速度分数
     */
    private double storeDeliverycredit = 5.0;
    /**
     * 店铺收藏数量
     */
    private int storeCollect = 0;
    /**
     * 店铺销量
     */
    private int storeSales = 0;
    /**
     * 售前客服
     */
    private String storePresales = "";
    /**
     * 售后客服
     */
    private String storeAftersales = "";
    /**
     * 工作时间
     */
    private String storeWorkingtime = "";
    /**
     * 是否自营店铺</br>
     * 0-否 1-是
     */
    private int isOwnShop;
    /**
     * 店铺Logo URL
     */
    private String storeLogoUrl;
    /**
     * 店铺条幅URL
     */
    private String storeBannerUrl;

    /**
     * 店铺头像URL
     */
    private String storeAvatarUrl;
    /**
     * 店铺设置的快递公司Id
     */
    private ShipCompany shipCompany;
    /**
     * 公司名称
     */
    private CompanyName companyName = CompanyName.of("");
    /**
     * 所在地
     */
    private String companyArea = "";
    /**
     * 所在地编号
     */
    private Integer companyAreaId = 0;
    /**
     * 结算周期
     */
    private int billCycle = 1;
    /**
     * 结算类型 1按月结/2按天结
     */
    private int billCycleType = 1;
    /**
     * 是否开启店铺装修 1-开启 0-关闭
     */
    private int decorationState = 0;
    /**
     * 是否仅显示店铺装修内容 1-是 0-否
     */
    private int decorationOnly = 0;
    /**
     * 店铺装修主色
     */
    private String decorationColor = "#483E39";
    /**
     * 店铺装修对应的专题编号
     */
    private int decorationId = 0;
    /**
     * 卖家服务
     */
    private StoreCommitment storeCommitment = StoreCommitment.of("");
    /**
     * 营业执照电子版
     */
    private String businessLicenceImage;
    /**
     * 营业执照地址
     */
    private String businessLicenceImageUrl;
    /**
     * 是否有营业执照
     */
    private int hasBusinessLicence;
    /**
     * 食品流通许可证电子版
     */
    private String foodCirculationPermitImage;
    /**
     * 食品流通许可证地址
     */
    private String foodCirculationPermitImageUrl;
    /**
     * 是否有食品流通许可证
     */
    private int hasFoodCirculationPermit;
    /**
     * 发布海外购商品
     */
    private int allowForeignGoods = 0;

    public String getStoreLogoUrl() {
        if (storeLogo == null || storeLogo.trim().equals("")) {
            storeLogoUrl = ShopConfig.getPublicRoot() + Common.DEFAULT_STORE_LOGO;
        }else{
            storeLogoUrl = ShopConfig.getUploadRoot() + storeLogo;
        }
        return storeLogoUrl;
    }


    public String getStoreBannerUrl() {
        if (storeBanner == null || storeBanner.trim().equals("")) {
            storeBannerUrl = ShopConfig.getPublicRoot() + Common.DEFAULT_STORE_BANNER;
        }else{
            storeBannerUrl = ShopConfig.getUploadRoot() + storeBanner;
        }
        return storeBannerUrl;
    }

    public String getStoreAvatarUrl() {
        if (storeAvatar == null || storeAvatar.trim().equals("")) {
            storeAvatarUrl = ShopConfig.getPublicRoot() + Common.DEFAULT_STORE_AVATAR;
        }else{
            storeAvatarUrl = ShopConfig.getUploadRoot() + storeAvatar;
        }
        return storeAvatarUrl;
    }

    /**
     * 返回结算周期与结算周期计算单位的整体描述
     * by hbj 2016/02/16
     * @return
     */
    public String getBillCyleDescription() {
        return billCycle + (billCycleType == BillCycleType.MONTH ? " 月" : " 天");
    }

    public String getBusinessLicenceImageUrl() {
        if (!StringUtils.isBlank(businessLicenceImage)) {
            businessLicenceImageUrl = ShopConfig.getUploadRoot() + businessLicenceImage;
        }
        return businessLicenceImageUrl;
    }

    public void setBusinessLicenceImageUrl(String businessLicenceImageUrl) {
        this.businessLicenceImageUrl = businessLicenceImageUrl;
    }

    public int getHasBusinessLicence() {
        if (StringUtils.isBlank(businessLicenceImage)) {
            return State.NO;
        } else {
            return State.YES;
        }
    }

    public String getFoodCirculationPermitImageUrl() {
        if (!StringUtils.isBlank(foodCirculationPermitImage)) {
            foodCirculationPermitImageUrl = ShopConfig.getUploadRoot() + foodCirculationPermitImage;
        }
        return foodCirculationPermitImageUrl;
    }

    public int getHasFoodCirculationPermit() {
        if (StringUtils.isBlank(foodCirculationPermitImage)) {
            return State.NO;
        } else {
            return State.YES;
        }
    }
}
